package com.framework.bas.util.linq;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unchecked")
public class FilterManager {

	private List<IFilter> flist = new ArrayList<IFilter>();

	public void add(IFilter filter) {
		if(filter != null){
			flist.add(filter);
		}
	}
	
	public List filter(ILinq linq){
		List list = linq.getList();
		for(IFilter fi : flist){
			List resultList = new ArrayList();
			for (int i=0;i<list.size();i++) {
				Object e = list.get(i);
				boolean isOk = fi.filter(linq,e);
				if(isOk){
					resultList.add(e);
				}
			}
			list = new ArrayList();
			list.addAll(resultList);
		}
		return list;
	}
}
